package com.fly.main;

import javax.sql.DataSource;

import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MainRun
{
    /**
     * JdbcTemplate
     * 
     * @param args
     * @see [类、类#方法、类#成员]
     */
    public static void main(String[] args)
    {
        GenericXmlApplicationContext context = new GenericXmlApplicationContext();
        context.setValidating(false);
        context.load("classpath*:application*.xml");
        context.refresh();
        log.info("★★★★★★★★ ApplicationContext = {}", context);
        int i = 1;
        for (String beanName : context.getBeanDefinitionNames())
        {
            log.info("{}.\t{}", i, beanName);
            i++;
        }
        DataSource datasource = context.getBean(DataSource.class);
        JdbcTemplate jdbcTemplate = new JdbcTemplate(datasource);
        jdbcTemplate.execute("drop table if exists t_student");
        jdbcTemplate.execute("create table t_student(id int not null,name varchar(50),primary key(id))");
        jdbcTemplate.execute("insert into t_student(id, name) values(1,'Jack')");
        jdbcTemplate.execute("insert into t_student(id, name) values(2,'Phil')");
        jdbcTemplate.execute("insert into t_student(id, name) values(3,'Jenny')");
        context.close();
    }
}
